import random

user = {
    1: {
        'name': '张三',
        'password': '123',
        '账户类型': 2,
        '国家': '中国',
        '省份': '河南',
        '街道': 'c',
        '门牌号': 'd',
        '余额': 10000000000
    },
    2: {
        'name': '张01',
        'password': '123',
        '账户类型': 1,
        '国家': '中国',
        '省份': '河南',
        '街道': 'c',
        '门牌号': 'd',
        '余额': 10100000000
    }
}
name = password = a = b = c = d = str()

#开户
def open_bank():
    id = random.randint(10000000, 99999999)

    if id in user:
        return '您已经在账户库中。'
    elif len(user) >= 100:
        return '账户库已满。'
    else:
        name = input('请输入姓名：')
        password = input('请输入密码：')
        while True:
            ida_type = int(input("请输入账户类型(1类，2类)："))
            if ida_type == 1 or ida_type == 2:
                print('类型选择成功')
                break
            else:
                print('类型选择错误，重新选择。')
        a = input('请输入国家：')
        b = input('请输入省份：')
        c = input('请输入街道：')
        d = input('请输入门牌号：')
        yu_e = int(input('请输入余额：'))
        user[id] = {'name': name, 'password': password, '账户类型': ida_type, '国家': a, '省份': b, '街道': c,
                    '门牌号': d, '余额': yu_e}
        print(f'开户成功，您的账号是：{id}')


#
# a = open_bank()
# print(a)
#


#判断银行卡类型
def id_type(id):
    if user[id]['账户类型'] == 1:
        return 1
    else:
        return 0

#银行卡类型,限额
def id_type_zhuanzhang(id,a_money):
    a = id_type(id)
    if a == 1:
        if a_money <= 50000 and a_money >= 0:
            return 1
        elif a_money > 50000:
            print("超出额度！")
        else:
            print('输入正确金额：')
    if a == 0:
        if a_money <= 20000 and a_money >= 0:
            return 2
        elif a_money > 20000:
            print("超出额度！")
        else:
            print('输入正确金额：')


#存钱！
def save_money():
    a = int(input('请输入账号：'))
    if a in user:
        maney = int(input('请输入要存入的金额：'))
        user[a]['余额'] += maney
        print(f'您的剩余余额是：{user[a]["余额"]}')
    else:
        print('请先开户')


# save_money()

#取钱
def draw_money():
    a = int(input('请输入账号：'))
    if a in user:
        pwd = input('请输入密码：')
        if pwd == user[a]['password']:
            d_my = int(input('请输入取出金额：'))
            type_a = id_type_zhuanzhang(a,d_my)
            if d_my <= user[a]["余额"] and (type_a == 1 or type_a == 2):
                user[a]["余额"] -= d_my
                print(f'您取出的金额是{d_my},您的余额是：{user[a]["余额"]}')
            elif d_my > user[a]["余额"]:
                print('余额不足！')
        else:
            print('密码错误！')
    else:
        print('请先开户')


# draw_money()
#转账
def transfer_accounts():
    a = int(input('请输入转出账号：'))
    b = int(input('请输入转入账号：'))
    if a in user and b in user:
        a_pwd = input(f'请输入{a}的密码：')
        if a_pwd == user[a]["password"]:
            t_money = int(input('请输入转账金额：'))
            zhuanzhang = id_type_zhuanzhang(a,t_money)
            if t_money <= user[a]['余额'] and (zhuanzhang == 1 or zhuanzhang == 2):
                user[a]['余额'] -= t_money
                user[b]['余额'] += t_money
                print(f'当前账户为：{a},余额为：{user[a]["余额"]}')
            elif t_money > user[a]["余额"]:
                print('余额不足！')
        else:
            print('密码错误！')
    elif a in user and b not in user:
        print('转入账号错误！')
    elif a not in user and b in user:
        print('转出账号错误！')
    else:
        print('转出和转入账号都错误。')##


# transfer_accounts()


#查询
def id_type_name(id):
    if user[id]['账户类型']==1:
        return '1型卡（金卡）'
    else:
        return '2型卡（普通卡）'
def select():
    a = int(input('请输入账号：'))
    if a in user:
        pwd = input('请输入密码：')
        id_tp_name = id_type_name(a)
        if pwd == user[a]['password']:
            print(f"""
            当前账号：{a}
            当前账户类型是：{id_tp_name}
            密码是：{pwd}
            余额是：{user[a]['余额']}
            您的住址是：{user[a]['国家']},{user[a]['省份']},{user[a]['街道']},{user[a]['门牌号']}
            当前账户的开户行是：中国农业银行的昌平沙河支行
            """)
        else:
            print('密码错误！')
    else:
        print('请先开户')


# select()


#菜单
def main():
    print('''
******************************
*    中国农业银行账户管理系统    *
******************************
*            选项            *
*         1. 开户            *
*         2. 存钱            *
*         3. 取钱            *
*         4. 转账            *
*         5. 查询            *
*         6. Bye             *
******************************
    ''')
    while True:
        a = int(input("请输入选项："))
        if a == 1:
            open_bank()
        elif a == 2:
            save_money()
        elif a == 3:
            draw_money()
        elif a == 4:
            transfer_accounts()
        elif a == 5:
            select()
        else:
            break

#启动
main()